//
// File: ppval.cpp
//
// MATLAB Coder version            : 5.4
// C/C++ source code generated on  : 27-Mar-2025 11:51:36
//

// Include Files
#include "ppval.h"
#include "rt_nonfinite.h"
#include "coder_array.h"
#include <cmath>

// Function Definitions
//
// Arguments    : const ::coder::array<double, 2U> &pp_breaks
//                const ::coder::array<double, 2U> &pp_coefs
//                double x
// Return Type  : double
//
namespace coder {
double ppval(const ::coder::array<double, 2U> &pp_breaks,
             const ::coder::array<double, 2U> &pp_coefs, double x)
{
  double v;
  int numTerms;
  numTerms = pp_coefs.size(1);
  if (std::isnan(x)) {
    v = x;
  } else {
    double xloc;
    int high_i;
    int low_i;
    int low_ip1;
    high_i = pp_breaks.size(1);
    low_i = 1;
    low_ip1 = 2;
    while (high_i > low_ip1) {
      int mid_i;
      mid_i = (low_i >> 1) + (high_i >> 1);
      if (((low_i & 1) == 1) && ((high_i & 1) == 1)) {
        mid_i++;
      }
      if (x >= pp_breaks[mid_i - 1]) {
        low_i = mid_i;
        low_ip1 = mid_i + 1;
      } else {
        high_i = mid_i;
      }
    }
    xloc = x - pp_breaks[low_i - 1];
    v = pp_coefs[low_i - 1];
    for (high_i = 2; high_i <= numTerms; high_i++) {
      v = xloc * v +
          pp_coefs[(low_i + (high_i - 1) * (pp_breaks.size(1) - 1)) - 1];
    }
  }
  return v;
}

} // namespace coder

//
// File trailer for ppval.cpp
//
// [EOF]
//
